unit CommonObj;

interface
uses SysUtils, Classes, kbmMWObject, kbmMWCustomMemoryStreamFormatter, kbmMWObjectUtils;

type
  IMyObject = interface(IkbmMWObject)
    ['{6DD3AB96-8C23-43E3-B0BB-0D231CF11655}']
    function GetAddress: string;
    function GetFirstName: string;
    function GetLastName: string;

    procedure SetAddress(const Value: string);
    procedure SetFirstName(const Value: string);
    procedure SetLastName(const Value: string);

    property FirstName: string read GetFirstName write SetFirstName;
    property LastName: string read GetLastName write SetLastName;
    property Address: string read GetAddress write SetAddress;
  end;

type
  TMyObject = class(TkbmMWObject, IMyObject)
  private
    FFirstName: string;
    FLastName: string;
    FAddress: string;

    function GetAddress: string;
    function GetFirstName: string;
    function GetLastName: string;
    procedure SetAddress(const Value: string);
    procedure SetFirstName(const Value: string);
    procedure SetLastName(const Value: string);
  public
    destructor Destroy; override;
    procedure Writer(AStreamFormatter: TkbmMWCustomMemoryStreamFormatter);
      override;
    procedure Reader(AStreamFormatter: TkbmMWCustomMemoryStreamFormatter);
      override;

  published

    property FirstName: string read GetFirstName write SetFirstName;
    property LastName: string read GetLastName write SetLastName;
    property Address: string read GetAddress write SetAddress;

  end;
implementation

{ TMyObject }

destructor TMyObject.Destroy;
begin
  inherited;
end;

function TMyObject.GetAddress: string;
begin
  result := FAddress;
end;

function TMyObject.GetFirstName: string;
begin
  result := FFirstName;
end;

function TMyObject.GetLastName: string;
begin
  result := FLastName;
end;

procedure TMyObject.SetAddress(const Value: string);
begin
  FAddress := Value;
end;

procedure TMyObject.SetFirstName(const Value: string);
begin
  FFirstName := Value;
end;

procedure TMyObject.SetLastName(const Value: string);
begin
  FLastName := Value;
end;

procedure TMyObject.Reader(AStreamFormatter:
  TkbmMWCustomMemoryStreamFormatter);
begin
  FFirstName := AStreamFormatter.ReadString('FIRSTNAME');
  FLastName := AStreamFormatter.ReadString('LASTNAME');
  FAddress := AStreamFormatter.ReadString('ADDRESS');
end;

procedure TMyObject.Writer(AStreamFormatter:
  TkbmMWCustomMemoryStreamFormatter);
begin
  AStreamFormatter.WriteString('FIRSTNAME', FFirstName);
  AStreamFormatter.WriteString('LASTNAME', FLastName);
  AStreamFormatter.WriteString('ADDRESS', FAddress);
end;

initialization
  kbmMWRegisterStreamableObject(TMyObject);

end.

